package com.sky.controller.admin;

import com.sky.controller.common.CommonShopController;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
public class ShopController {
    private static final String KEY = "SHOP_STATUS";
    private final RedisTemplate<Object,Object> redisTemplate;
    private final CommonShopController commonShopController;

    @Autowired
    public ShopController(RedisTemplate<Object, Object> redisTemplate, CommonShopController commonShopController) {
        this.redisTemplate = redisTemplate;
        this.commonShopController = commonShopController;
    }

    /**
     * 设置店铺状态
     * @param status 状态
     * @return Result
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺的营业状态")
    public Result<?> setStatus(@PathVariable Integer status){
        log.info("执行 管理端设置营业状态 接口");
        log.info("设置当前店铺营业状态为：{}", status==1?"营业中":"打样中");
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    /**
     * 查看店铺状态
     * @return Result
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺的营业状态")
    public Result<Integer> getStatus(){
        log.info("执行 管理端查看营业状态 接口");
        return commonShopController.getStatus();
    }
}
